home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
progjour
/
1991
/
06
/
scribble.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-31
|
2KB
|
70 lines
/*---------------------------------------------------------
Drawing with the mouse
---------------------------------------------------------*/
#include <windows.h>
#include "winclass.h"
#include "initinst.h"
class SCRIBBLE : public MAINWINDOW
{
protected:
HDC hDC;
LPSTR GetClassName() {return "Scribble";};
void MouseMove ();
void LButtonDown ();
void LButtonUp ();
public:
SCRIBBLE () { hDC = NULL; };
};
/*---------------------------------------------------------
When the user pushes down the left mouse button,
get a device context and set the current position
---------------------------------------------------------*/
void SCRIBBLE::LButtonDown ()
{
hDC = GetDC (hWnd);
if (hDC)
{
MoveTo (hDC, getx(), gety());
ShowCursor (FALSE); // Turn off the mouse arrow.
SetCapture (hWnd); // Capture the mouse.
}
}
/*---------------------------------------------------------
When the mouse moves from one pixel position to another,
draw a line if the device context is set
---------------------------------------------------------*/
void SCRIBBLE::MouseMove ()
{
if (hDC)
LineTo (hDC, getx(), gety());
}
/*---------------------------------------------------------
When the user lifts up on the left mouse button,
release the device context
---------------------------------------------------------*/
void SCRIBBLE::LButtonUp ()
{
if (hDC)
{
ReleaseDC (hWnd, hDC);
hDC = NULL;
ShowCursor (TRUE); // Turn the mouse arrow back on.
ReleaseCapture(); // Release the mouse.
}
}
/*---------------------------------------------------------
Create a Scribble window
---------------------------------------------------------*/
BOOL InitInstance()
{
static SCRIBBLE scribble;
return scribble.Make();
}